<!--
 * @Author: your name
 * @Date: 2021-12-15 20:25:13
 * @LastEditTime: 2021-12-16 20:58:44
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \day7\my-app\src\components\Right.vue
-->

/<template>
  <div class="right">
    <div v-for="(item, index) in list" :key="index" class="right_con">
      <b ref="rs">{{ item.name }}</b>
      <dl v-for="(v, i) in item.child" :key="i" @click="toDetail(v.id)">
        <dt><img :src="v.img" alt="" /></dt>
        <dd>
          <p>{{ v.name }}</p>
          <p>{{ v.title }}</p>
          <div class="dd_con">
            <span style="color:red">{{ v.price }}</span>
            <p>
              <button v-if="v.count>0" @click.stop="redNums(v.id)">-</button>
              <span v-if="v.count>0">{{ v.count }}</span>
              <button @click.stop="addNums(v.id)">+</button>
            </p>
          </div>
        </dd>
      </dl>
    </div>
  </div>
</template>

<script>
import {mapActions} from "vuex"
export default {
  props: ["list","activeIndex"],
  mounted() {
      this.bus.$on('aa', (index)=>{
          this.i=index
          this.$refs.rs[this.i].scrollIntoView({behavior:"smooth"})
      })
  },
  methods: {
    ...mapActions(["addNum","redNum"]),
    //   跳转详情
      toDetail(id){
        console.log(id);
        this.$router.push({
            path:"/detail",
            query:{
                id
            }
        })
      },
      // 添加
     addNums(id){
        this.addNum({id})
     },
    //  减减
    redNums(id){
        this.redNum({id})
    },
    
  }
};
</script>

<style lang="scss" scoped>
.right_con {
  width: 100%;
  dl {
    display: flex;
    align-items: center;
    dt {
      img {
        width: 100px;
        height: 100px;
      }
    }
    dd {
      line-height: 30px;
      .dd_con {
        display: flex;
        height: 15px;
        line-height: 15px;
        justify-content: space-between;
        align-items: center;
        padding-left: 5px;
        button {
          width: 15px;
          height: 15px;
          border: 1px solid #ccc;
          margin: 0px 5px;
        }
      }
    }
  }
}
</style>